# ============================================================
# by howlink *
# Filename       : changearch.sh
#
# Description:  create dataguard primary standbyredo logfile 
# exmple: ./changeArch.sh orcl orcl /u01/app/oracle/product/11g/db_1/dbs/arch
# =============================================================
#! /bin/sh
set +x
if [ $# -lt 2 ]; then
    echo "must input 2 parameters"
   exit 1
fi

sid=$1
instid=$2

spath=/opt/howlink/lb-agent/scripts/oracle/dg
arch=`$spath/sqlplusShell.sh $spath/getArch.sql $1 $2`

orauser=`cat /opt/howlink/lb-agent/application.properties | grep "^agent.oracle-user" | awk -F'=' '{ print $2 }' | sed 's/ //g'`
if [ -z "$orauser" ];then
    orauser=`ps -ef | grep ora_pmon | grep -v grep | head -n1 | sed -e 's/^[ \t]*//' | cut -d" " -f1`
fi
if [ -z "$orauser" ];then
    orauser=oracle
fi

orahome=`cat /opt/howlink/lb-agent/application.properties | grep "^agent.oracle-home" | awk -F'=' '{ print $2 }' | sed 's/ //g'`
if [ -z "$oraclehome" ];then
    orahome=`grep -wi "$sid:"  $otab | grep "^$sid" | head -n1 | cut -f2 -d":"`
fi


if [[ $arch == "ARCHIVELOG" ]]; then
    echo "instance is in archivelog mode"
    exit 0
fi

lpath=$orahome/dbs/arch

if [ ! -e "$lpath" ] ;then
    mkdir -p $lpath
    chown -R $orauser $lpath
fi
chown -R $orauser $lpath
retval=`$spath/sqlplusShell.sh $spath/changeArch.sql $1 $2 $lpath`
export status=$retval
echo $retval
